package com.kanche.bigbaby.collection.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;

/**
 * Created by Chenshao_Young on 15/4/30.
 */
public class YesOrNoDialog  extends KancheDialogFragment{
    public static final String TITLE = "title";
    public static final String MESSAGE = "message";
    public static final String STRPositive = "strPositive";
    public static final String STRNegative = "strNegative";

    public String strPositive = "确定";
    public String strNegative = "取消";

        String title = "";
        String message = "";

    private OnClick onClick;

    public OnClick getOnClick() {
        return onClick;
    }

    public void setOnClick(OnClick onClick) {
        this.onClick = onClick;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        if (null == getArguments()){
            return null;
        } else {
            title = getArguments().getString(TITLE,"提示");
            message = getArguments().getString(MESSAGE,"确定吗");
            strPositive = getArguments().getString(STRPositive,"确定");
            strNegative = getArguments().getString(STRNegative,"取消");

        }

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(title);
        builder.setMessage(message);
        builder.setCancelable(true);

        builder
                .setPositiveButton(strPositive, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        onClick.onPositive();
                    }
                })
                .setNegativeButton(strNegative, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        onClick.onNegative();
                    }
                });
        return builder.create();
    }

    public interface OnClick{
          void onPositive();
          void onNegative();
    }
}
